<?php

/**
 * BlogPost form.
 *
 * @package    HugoHamon
 * @subpackage form
 * @author     Hugo Hamon <hugo.hamon@sensio.com>
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class BlogPostForm extends BaseBlogPostForm
{
  protected $languages = array(
    'en' => 'English',
    'fr' => 'French'
  );

  public function configure()
  {
    $this->useFields(array(
      'author_id', 'title', 'slug', 'lang', 
      'tags', 'source_excerpt', 
      'source_content', 'published_at',
      'is_published', 'is_commentable',
      'is_moderated', 'categories_list'
    ));

    $this->widgetSchema['title']->setAttribute('size', 60);
    $this->widgetSchema['slug']->setAttribute('size', 60);
    $this->widgetSchema['tags']->setAttribute('size', 60);
    $this->validatorSchema['slug'] = new sfValidatorAnd(array(
      new sfValidatorRegex(
        array('pattern' => $this->getSlugPattern()),
        array('invalid' => 'The slug format is not valid.')
      ),
      new sfValidatorDoctrineUnique(
        array('column' => array('slug'), 'model' => 'BlogPost', 'primary_key' => 'slug'),
        array('invalid' => 'This slug is already taken by an other post.')
      )
    ));
    
    $this->widgetSchema['lang'] = new sfWidgetFormChoice(
      array(
        'choices' => $this->languages,
        'expanded' => true
      )
    );
    
    $this->validatorSchema['lang'] = new sfValidatorChoice(
      array('choices' => array_keys($this->languages)),
      array('invalid' => 'Choosen language is not a valid language value.')
    );
    
    $this->widgetSchema['source_excerpt']->setAttributes(array('class' => 'markItUp', 'cols' => 85, 'rows' => 10));
    $this->widgetSchema['source_content']->setAttributes(array('class' => 'markItUp', 'cols' => 85, 'rows' => 40));
    
    $this->widgetSchema['categories_list']->setOption('expanded', true);
    
    $this->widgetSchema->setHelp('title', 'The title must be explicit and meaningfull.');
    $this->widgetSchema->setHelp('slug', 'The slug must be a unique string composed of A-Z, 0-9 and dash characters.');
    $this->widgetSchema->setHelp('source_excerpt', 'Add a short excerpt to introduce the post content.');
    $this->widgetSchema->setHelp('source_content', 'Write your content with the markdown editor.');
    $this->widgetSchema->setHelp('is_published', 'Tick the box to publish the blog post.');
    $this->widgetSchema->setHelp('is_commentable', 'Tick the box to authorize comments.');
    $this->widgetSchema->setHelp('is_moderated', 'Tick the box to force new comments to be validated.');
    $this->widgetSchema->setHelp('published_at', 'Define a publication date in the future.');
  }
}
